package com.winning.sjzc.common.controller;

import com.winning.sjzc.common.entity.po.SysZcjgEntity;
import com.winning.sjzc.common.entity.vo.JgTreeEntity;
import com.winning.sjzc.common.service.CommonService;
import com.winning.sjzc.common.utils.JgTreeUtil;
import com.winning.sjzc.common.utils.ResponseEntity;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
 * @ClassName CommonController
 * @Description TODO
 * @Author WJX
 * @Date 2020/3/2 17:11
 **/
@Slf4j
@Controller
@RequestMapping("/dict")
public class CommonController {

    @Autowired
    private CommonService commonService;

    @PostMapping("/queryJgList")
    @ResponseBody
    public ResponseEntity queryJgList(@RequestBody Map paraMaps){
        String jgbm = paraMaps.get("jgbm")+"";
        JgTreeUtil jtu = new JgTreeUtil();
        List<JgTreeEntity> list = commonService.findJgTree();
        Map<String, Object> jgInfoArray = new LinkedHashMap<>();
        SysZcjgEntity sysZcjgEntity = commonService.getJgInfo(jgbm);
        jgInfoArray.put("id", jgbm);
        jgInfoArray.put("name", sysZcjgEntity.getJgmc());
        jgInfoArray.put("pId", sysZcjgEntity.getSjjgbm());
        jgInfoArray.put("jglb", sysZcjgEntity.getJglb());
        List<Object> jgTreeList = jtu.jgTreeList(list, jgbm);
        jgTreeList.add(jgInfoArray);
        return ResponseEntity.ok().put("jgTreeList", jgTreeList);
    }
}
